package com.hqu.ms.ui.view;

import com.googlecode.androidannotations.annotations.Click;
import com.googlecode.androidannotations.annotations.EViewGroup;
import com.googlecode.androidannotations.annotations.TextChange;
import com.googlecode.androidannotations.annotations.ViewById;
import com.hqu.ms.R;

import android.content.Context;
import android.text.InputType;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

@EViewGroup(R.layout.ms_comment_user_item)
public class UserItemView extends LinearLayout {
	@ViewById
	EditText etInput;
	
	@ViewById
	LinearLayout llUserLayout;
	
	@ViewById
	Button btnDelete;

	public UserItemView(Context context) {
		super(context);
	}

	public UserItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	public String getEdittextString(){
		return etInput.getEditableText().toString();
	}
	public void setInputHintStr(String str) {
		etInput.setHint(str);
	}
	
	public void setInputForcus(boolean isforcus){
		etInput.setFocusable(isforcus);
	}
	public  void requestInputForcus(){
		 etInput.requestFocus();
	}
	public void setBtnDelVisible() {
		setBtnDelVisible(View.INVISIBLE);
		llUserLayout.setBackgroundResource(R.drawable.input_normal);
		etInput.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				if (hasFocus) {
					if(etInput.getEditableText().toString().length() > 0){
						btnDelete.setVisibility(View.VISIBLE);
					}
					llUserLayout.setBackgroundResource(R.drawable.input_selected);
				} else {
					btnDelete.setVisibility(View.GONE);
					llUserLayout.setBackgroundResource(R.drawable.input_normal);
				}
			}
		});
	}
	
	public void setEditTextAnim(Animation anim){
		etInput.startAnimation(anim);
	}
	
	@TextChange(R.id.etInput)
	void textChangeInput(){
		if(etInput.getEditableText().toString().length() > 0 && etInput.isFocused()){
			btnDelete.setVisibility(View.VISIBLE);
		}
	}
	
	public void setBtnDelVisible(int visible) {
		btnDelete.setVisibility(visible);
	}
	
	public void setInputStr(String string){
		etInput.setText(string);
	}
	
	public void setInputFocus(){
		etInput.requestFocus();
	}
	@Click
	void btnDeleteClicked() {
		etInput.setText("");
		etInput.requestFocus();
	}
}
